#!/usr/bin/python
# -*- coding: utf-8 -*-

import socket

ADDRESS = '192.168.1.9'
PORT= 10001

STARTING_SPEED = 'M   '
LOW_SPEED = 'M   '
NORMAL_SPEED = 'M   '
HIGH_SPEED = 'M   '

STOP_COMMAND = '5'
LASER_ON_COMMAND = 'l'
LASER_OFF_COMMAND = 'L'
RECV_BYTES = 256

class Pos:
    
    def __init__ (self, x, y, tetha):
        self.x, self.y = x, y
        self.tetha = tetha

class Robot:

    def __init__ (self, address = ADDRESS):
        # Robot's IP address.
        self.__address = address

        # Robot connection.
        self.__socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        try:
            self.__socket.connect((address, PORT))
        except:
            print "Error connecting to %s" % (HOST)
            sys.exit(0)

        print 'Starting engines...'
        self.__socket.send(STARTING_SPEED)
        self.__socket.recv(RECV_BYTES)

    def move (self, pos, speed):
        pass

    # Turn degrees to dir.
    def turn (self, dir, degrees):
        pass

    # Explore and take images around pos.
    def explore (self, pos):
        pass

    # Return the array of bytes of the image captured.
    def capture (self, res):
        pass

    def setLaser (self, on = True):
        if on:
            self.__socket.send(LASER_ON_COMMAND)
        else:
            self.__socket.send(LASER_OFF_COMMAND)
        self.__socket.recv(RECV_BYTES)

    def stop (self):
        self.__socket.send(STOP_COMMAND)
        self.__socket.recv(RECV_BYTES)

    def destroy (self):
        self.stop()
        self.__socket.close()

if __name__ == '__main__':
    r = Robot()
    r.destroy()
